package com.itcs.app.tran;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itcs.app.util.TerminalStatus;
import com.itcs.dubbo.service.DubboServiceAdapter;
import com.itcs.trading.mapper.TerminalLinksRgtMapper;
import com.itcs.trading.model.TerminalLinksRgt;

/**
 * 通讯盒下线
 * 
 * @author LiuPeng
 * @date 2018年2月28日
 * 
 */
@Component
public class BoxChannelInactive implements DubboServiceAdapter {

	private Log logger = LogFactory.getLog(getClass());

	@Autowired
	private TerminalLinksRgtMapper terminalLinksRgtMapper;

	@Override
	public String getTrancode() {
		return "boxChannelInactive";
	}

	@Override
	public Map<String, Object> exchange(Map<String, Object> reqRecord) {
		try {
			String deviceId = reqRecord.get("deviceId").toString();
			String channelId = reqRecord.get("channelId").toString();
			
			TerminalLinksRgt link = terminalLinksRgtMapper.selectByPrimaryKey(channelId);
			link.setTerminalStatus(TerminalStatus.车道通信断开);
			terminalLinksRgtMapper.updateByPrimaryKey(link);
			
			logger.info("通讯盒[" + deviceId + "]下线.");
		} catch (Exception e) {
			logger.error("通讯盒下线处理失败", e);
		}
		return null;
	}

}
